package 软件秘笈_设计模式;


public class 抽像工厂方法模式 {
    public static void main(String[] args) {
        IKfcBactory iKfcBactory = new ChinaKfcFactory();
        Customer customer = new Customer(iKfcBactory);
        float hamH = customer.orderHamburg(10);
        System.out.println(hamH);
    }
}
abstract class AbstractBaseFood{
    protected String kind;
    protected int num;
    protected float price;
    public float totalPrice(){
        return this.num * this.price;
    }
}
interface IFood{
    void printMesage();
}
abstract class Hamburg extends AbstractBaseFood implements IFood{
    public void printMesage(){
        System.out.println("--"+this.kind+"风味汉堡,\t 单价:"+this.price+",\t 数量"+this.num+"合计:"+this.totalPrice());
    }
}
abstract class chickenwings extends AbstractBaseFood implements IFood{
    public void printMesage(){
        System.out.println("--"+this.kind+"风味鸡翅,\t 单价:"+this.price+",\t 数量"+this.num+"合计:"+this.totalPrice());
    }
}
class ChinaHanburm extends Hamburg{
    public ChinaHanburm(int num){
        this.kind = "麻辣";
        this.price = 14.0f;
        this.num = num;
    }
}
class ChinaChickenWings extends chickenwings{
    public ChinaChickenWings(int num){
        this.kind = "奥尔良";
        this.price = 2.5f;
        this.num = num;
    }
}
interface IKfcBactory{
    public Hamburg createHamburg(int num);
    public chickenwings createChicken(int num);
}
class ChinaKfcFactory implements IKfcBactory{

    @Override
    public Hamburg createHamburg(int num) {
        return new ChinaHanburm(num);
    }

    @Override
    public chickenwings createChicken(int num) {
        return new ChinaChickenWings(num);
    }
}
class Customer{
    private IKfcBactory iKfcBactory;
    public Customer(IKfcBactory iKfcBactory){
        this.iKfcBactory = iKfcBactory;
    }
    public float orderHamburg(int num){
        Hamburg hamburg = iKfcBactory.createHamburg(num);
        hamburg.printMesage();
        return hamburg.totalPrice();
    }
    public float orderChickenWings(int num){
        chickenwings hamburg = iKfcBactory.createChicken(num);
        hamburg.printMesage();
        return hamburg.totalPrice();
    }
}